package com.asset.inventory.adapter

import android.view.LayoutInflater
import android.view.TextureView
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.asset.inventory.R
import com.asset.inventory.model.ConfigInfo

/**
 * 页面名称：配置信息适配器
 * 创建时间  2021/04/10 17:36
 */
open class ConfigInfoAdapter(private val mList: MutableList<ConfigInfo>,private val onItemClickListener: (Int) -> Unit): RecyclerView.Adapter<ConfigInfoAdapter.ViewHolder>(){


    class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
        val contentTv: TextView = itemView.findViewById(R.id.content)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_config,parent,false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int = mList.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.contentTv.text = mList[position].name
        holder.itemView.setOnClickListener {
            onItemClickListener.invoke(position)
        }
    }
}